<style>
    .manager-mg{
        background:#FFFEE6;
        color:#8F5700;
        padding:12px;
    }
    .manager-mg-tip{
        width:16px;
        height:16px;
        margin-right:8px;
        float:left;
    }
    /*    #closeTip{
            background: rgba(0, 0, 0, 0) url("../css/icons/tabs_icons.png") no-repeat scroll -34px center;
            display: block;
        }*/
    #search{

    }
</style>
<script type="text/javascript">

    function addManager() {
        $('#manager-input-username').removeAttr('disabled');
        $('#manager-input-username').removeAttr('readonly');
        $('#manager-dlg').dialog('open').dialog('setTitle', '添加管理员');
        $('#manager-dlg-fm').form('clear');
        url = '<?php echo $this->config->item('base_url'); ?>system/addManager';
    }
    function editManager() {
        $('#manager-input-username').attr('disabled', 'true');
        $('#manager-input-username').attr('readonly', 'readonly');
        var row = $('#manager-list').datagrid('getSelected');
        if (row) {
            $('#manager-dlg').dialog('open').dialog('setTitle', '编辑管理员');
            row.pwd = null;
            $('#manager-dlg-fm').form('load', row);
            $.ajax({
                url: '<?php echo $this->config->item('base_url'); ?>system/getManagerDetailPermissionList?id=' + row.id,
                method: 'post',
                success: function (re) {
                    var obj = $.parseJSON(re);
                    $('#manager-powertree').combotree('setValues', obj);
                }
            });
            $.ajax({
                url: '<?php echo $this->config->item('base_url'); ?>system/getManagerGroupPermissionList?id=' + row.id,
                method: 'post',
                success: function (re) {
                    var obj = $.parseJSON(re);
                    console.log(obj);
                    $('#manager-powertree-group').combotree('setValues', obj);
                }
            });
            url = '<?php echo $this->config->item('base_url'); ?>system/editManager?id=' + row.id;
        } else {
            $.messager.confirm('错误', '请左击选中条目');
        }
    }
    function saveManager() {
        $('#manager-dlg-fm').form('submit', {
            url: url,
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (result) {
                var result = eval('(' + result + ')');
                if (result.errorMsg) {
                    $.messager.show({
                        title: '保存失败',
                        msg: result.errorMsg
                    });
                } else {
                    $('#manager-dlg').dialog('close');
                    $('#manager-list').datagrid('reload');
                }
            }
        });
    }
    function removeManager() {
        var row = $('#manager-list').datagrid('getSelected');
        if (row) {
            $.messager.confirm('提醒', '删除的用户将无法恢复', function (r) {
                if (r) {
                    $.post('<?php echo $this->config->item('base_url'); ?>system/deleteManager', {id: row.id}, function (result) {
                        if (result) {
                            $('#manager-list').datagrid('reload');
                        } else {
                            $.messager.show({
                                title: '删除失败',
                                msg: result.errorMsg
                            });
                        }
                    }, 'json');
                }
            });
        } else {
            $.messager.confirm('提醒', '请左击选中删除条目');
        }
    }
    function searchManager() {
        $('#manager-list').datagrid('load', {
            username: $('#manager_name').val(),
            power: $('#manager_power').combobox('getValue')
        });
    }
    //添加右击菜单内容
    function onRowMenuManager(e, rowIndex, rowData) {
        e.preventDefault();
        var selected = $("#manager-list").datagrid('getRows'); //获取所有行集合对象
        selected[rowIndex].id; //index为当前右键行的索引，指向当前行对象
        $('#manager-dlg_menu').menu('show', {
            left: e.pageX,
            top: e.pageY
        });
    }
</script>
<div class="manager-mg">
    <div class="manager-mg-tip icon-tip"></div>
    <div>温馨提示：在列表中点击左键可以选中条目</div>
    <div class="manager-mg-tip icon-tip"></div>
    <div>温馨提示：在列表中点击右键可以弹出操作菜单</div>
    <!--    <a id="closeTip"></a>-->
</div>
<!--数据表格-->
<table id="manager-list" class="easyui-datagrid"  title="管理员列表" toolbar="#manager-tb"
       url="<?php echo $this->config->item('base_url'); ?>system/getManagerList"
       rownumbers="true" pagination="true"
       singleSelect="true" fitColumns="true"
       data-options ="onRowContextMenu:onRowMenuManager"
       >
    <thead>
        <tr>
            <th field="id" align="center" width="50">ID</th>
            <th field="username" align="center" width="80">用户名</th>
            <th field="power" align="center" width="70">权限评类</th>
            <th field="phone" align="center" width="70">手机</th>
            <th field="email" align="center" width="70">邮箱</th>
            <th field="note" align="center" width="120">简介</th>
        </tr>
    </thead>
</table>
<!--工具栏及搜索框-->
<div id="manager-tb" style="padding:10px;height:auto">
    <div>
        <a class="easyui-linkbutton" onclick="addManager()" iconCls="icon-add" plain="true"></a>
        <a class="easyui-linkbutton" onclick="removeManager()" iconCls="icon-remove" plain="true"></a>
        <a class="easyui-linkbutton" onclick="editManager()" iconCls="icon-edit" plain="true"></a>
    </div>
    <div style="padding:10px;">
        指定用户名：<input id="manager_name" style="width:80px">
        指定权限评级：
        <input id="manager_power" panelHeight="auto" class="easyui-combobox" style="width:100px" 
               data-options="valueField: 'id',textField: 'text'"
               url="<?php echo $this->config->item('base_url'); ?>system/getGeneralPermissionList">
        <button onclick="searchManager()">搜索</button>
        <button onclick="$('#manager_name').val('');$('#manager_power').combobox('setValue', '999');">重置</button>
    </div>
</div>
<!--编辑弹框-->
<div id="manager-dlg" class="easyui-dialog" style="width:auto;height:auto;padding:10px 20px"
     closed="true" buttons="#manager-dlg-buttons">
    <form id="manager-dlg-fm" method="post">
        <div class="fitem">
            <label>用户名:</label>
            <input id="manager-input-username" name="username">
        </div>
        <div id="manager-input-pwd" class="fitem">
            <label>密码:</label>
            <input name="pwd" type="password">
        </div>
        <div class="fitem">
            <label>手机:</label>
            <input name="phone">
        </div>
        <div class="fitem">
            <label>邮箱:</label>
            <input name="email" class="easyui-validatebox" validType="email">
        </div>
        <div class="fitem">
            <label>通用权限:</label>
            <select id="manager-powertree" name="powertree[]" class="easyui-combotree" panelHeight="auto" style="width:150px;" multiple
                    data-options="url:'<?php echo $this->config->item('base_url'); ?>system/getDetailPermissionTree'">
            </select>
        </div>
        <div class="fitem">
            <label>客服管理权限:</label>
            <select id="manager-powertree-group" name="grouptree[]" class="easyui-combotree" panelHeight="auto" style="width:150px;" multiple
                    data-options="url:'<?php echo $this->config->item('base_url'); ?>service/getServiceGroupTree'">
            </select>
        </div>
        <div class="fitem">
            <label>简介:</label>
            <input name="note">
        </div>
    </form>
</div>
<div id="manager-dlg-buttons">
    <a class="easyui-linkbutton" iconCls="icon-ok" onclick="saveManager()">保存</a>
    <a class="easyui-linkbutton" iconCls="icon-cancel" onclick="$('#manager-dlg').dialog('close')">取消</a>
</div>
<!--右键菜单-->
<div id="manager-dlg_menu" class="easyui-menu" style="width:120px;">
    <div onClick="editManager()" data-options="iconCls:'icon-edit'">修改</div>
    <div onClick="addManager()" data-options="iconCls:'icon-add'">添加</div>
    <div onClick="removeManager()" data-options="iconCls:'icon-remove'">删除</div>
    <div class="menu-sep"></div>
    <div onClick="$('#manager-list').datagrid('reload');" data-options="iconCls:'icon-reload'">刷新</div>
</div>